package com.yong.websocket.config;


import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class WebSocketConfig {

    @PostConstruct
    public static void init(){
        final HappyChatServer server = new HappyChatServer(9688);
        server.init();
        server.start();
        // 注册进程钩子，在JVM进程关闭前释放资源
        Runtime.getRuntime().addShutdownHook(new Thread(){
            @Override
            public void run(){
                server.shutdown();
                System.exit(0);
            }
        });
        System.out.println("webSocket在依赖注入完成后自动调用");
    }
}
